//
//  NewsInsuranceCell.m
//  CarUser
//
//  Created by 王森林 on 2019/1/18.
//  Copyright © 2019年 王森林. All rights reserved.
//

#import "NewsInsuranceCell.h"
#import "HomeDetailView.h"
#import "NewsInsureanceViewController.h"
@interface NewsInsuranceCell()
@property  (nonatomic, strong) UIView *bgView;
@property  (nonatomic, strong) HomeDetailView *homeDetailView;
//@property  (nonatomic, strong) NSArray *imgsAry;
@end

@implementation NewsInsuranceCell

-(void)createUIWithData
{
    [self.contentView  removeAllSubviews];
    self.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.homeDetailView];
    [self createConstraint];
    
    float width = (BOUNDWIDTH - 30 - 20)/3;
    UIButton *btn1  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(15, 60, width, 160);
    [btn1 setBackgroundImage:IMG(@"car_test4") forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(handleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:btn1];
    
    
    UIButton *btn2  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(15+width+10, 60, width, 75);
//    [btn2 setBackgroundImage:IMG(@"car_test4") forState:UIControlStateNormal];
    btn2.backgroundColor  = RGB(50, 50, 50);
    [btn2 addTarget:self action:@selector(handleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:btn2];
    
    UIImageView *iconImageView2 = [[UIImageView alloc] init];
    iconImageView2.frame = CGRectMake((width-30)/2, 10, 30, 30);
    iconImageView2.image = IMG(@"new1");
    [btn2 addSubview:iconImageView2];
    UILabel *iconTitle2  = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, width, 14)];
    iconTitle2.text = @"机动车损失险";
    iconTitle2.font = FONT_SIZE(12);
    iconTitle2.textColor =  [UIColor whiteColor];
    iconTitle2.textAlignment = NSTextAlignmentCenter;
    [btn2 addSubview:iconTitle2];
    
    
    UIButton *btn3  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn3.frame = CGRectMake(15+width+10, 60+85, width, 75);
//    [btn3 setBackgroundImage:IMG(@"car_test4") forState:UIControlStateNormal];
     btn3.backgroundColor  = RGB(50, 50, 50);
    [btn3 addTarget:self action:@selector(handleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:btn3];
    
    UIImageView *iconImageView3 = [[UIImageView alloc] init];
    iconImageView3.frame = CGRectMake((width-30)/2, 10, 30, 30);
    iconImageView3.image = IMG(@"new2");
    [btn3 addSubview:iconImageView3];
    UILabel *iconTitle3  = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, width, 14)];
    iconTitle3.text = @"机动车损失险";
    iconTitle3.font = FONT_SIZE(12);
    iconTitle3.textColor =  [UIColor whiteColor];
    iconTitle3.textAlignment = NSTextAlignmentCenter;
    [btn3 addSubview:iconTitle3];
    
    
    UIButton *btn4  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn4.frame = CGRectMake(15+(width+10)*2, 60, width, 75);
//    [btn4 setBackgroundImage:IMG(@"car_test4") forState:UIControlStateNormal];
     btn4.backgroundColor  = RGB(50, 50, 50);
    [btn4 addTarget:self action:@selector(handleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:btn4];
    
    UIImageView *iconImageView4 = [[UIImageView alloc] init];
    iconImageView4.frame = CGRectMake((width-30)/2, 10, 30, 30);
    iconImageView4.image = IMG(@"new2");
    [btn4 addSubview:iconImageView4];
    UILabel *iconTitle4  = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, width, 14)];
    iconTitle4.text = @"机动车损失险";
    iconTitle4.font = FONT_SIZE(12);
    iconTitle4.textColor =  [UIColor whiteColor];
    iconTitle4.textAlignment = NSTextAlignmentCenter;
    [btn4 addSubview:iconTitle4];
    
    UIButton *btn5  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn5.frame = CGRectMake(15+(width+10)*2, 60+85, width, 75);
//    [btn5 setBackgroundImage:IMG(@"car_test4") forState:UIControlStateNormal];
    btn5.backgroundColor  = RGB(50, 50, 50);
    [btn5 addTarget:self action:@selector(handleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:btn5];
    
    UIImageView *iconImageView5 = [[UIImageView alloc] init];
    iconImageView5.frame = CGRectMake((width-30)/2, 10, 30, 30);
    iconImageView5.image = IMG(@"new1");
    [btn5 addSubview:iconImageView5];
    UILabel *iconTitle5  = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, width, 14)];
    iconTitle5.text = @"机动车损失险";
    iconTitle5.font = FONT_SIZE(12);
    iconTitle5.textColor =  [UIColor whiteColor];
    iconTitle5.textAlignment = NSTextAlignmentCenter;
    [btn5 addSubview:iconTitle5];
   
    
}
- (void)handleBtnAction:(id)sender
{
    NewsInsureanceViewController *controller = [[NewsInsureanceViewController alloc] init];
    [[self viewController].navigationController pushViewController:controller animated:YES];
    
}

- (void)createConstraint
{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(0);
        (void)make.left.and.right;
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
    }];
    
    [self.homeDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_top).offset(0);
        (void)make.left.and.right;
        make.height.mas_equalTo(48);
    }];
    

    
}

- (void)setData:(id)data
{
//    self.imgsAry = @[@"car_test4",@"car_test4",@"car_test4",@"car_test4",@"car_test4"];
     [self createUIWithData];
}


-  (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
    
}



- (HomeDetailView *)homeDetailView
{
    if (!_homeDetailView) {
        _homeDetailView = [[HomeDetailView alloc] initWithType:HOME_DETAIL_TYPE_INSURANCE withBlock:^(id  _Nonnull response) {
            NewsInsureanceViewController *controller = [[NewsInsureanceViewController alloc] init];
             controller.hidesBottomBarWhenPushed = YES;
            [[self viewController].navigationController  pushViewController:controller animated:YES];
        }];
    }
    return _homeDetailView;
}

@end
